<?php
namespace App\Utils\Service;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

class SmsSender
{
    private $connection;
    private $channel;

    public function __construct()
    {
        $this->connection = new AMQPStreamConnection(
            '10.0.4.13',
           5672,
            'guest',
           'guest',
            '/'
        );

        $this->channel = $this->connection->channel();
        $this->channel->queue_declare('sms_queue', false, false, false, false);
    }

    public function send($message)
    {
        $msg = new AMQPMessage($message);
        $this->channel->basic_publish($msg, '', 'sms_queue');

    }

    public function __destruct()
    {
        $this->channel->close();
        $this->connection->close();
    }
}
